package com.itheima.homework05;

import java.math.BigDecimal;

/*
有以下 double 数组：
double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
请编程计算它们的总值及平均值(四舍五入保留小数点后 2 位)

 */
public class work1 {
    public static void main(String[] args) {

        double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
        double sum=0.0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        BigDecimal b1=new BigDecimal(sum);
        BigDecimal b2=new BigDecimal(arr.length);

        System.out.println(b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP));

    }
}
